//
// Created by sgyt on 2020/1/17.
//
#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <string.h>
int main(int argc,char *argv[])
{
    struct utsname usys;
    int res = uname(&usys);
    if(res < 0 )
    {
        perror("uname is error\n");
    }
    printf("sysname:[%s]\n",usys.sysname);
    printf("machine:[%s]\n",usys.machine);
    printf("version:[%s]\n",usys.version);
    printf("release:[%s]\n",usys.release);

    int len = 64;
    char hostname[len];
   // memset(hostname,0x00, sizeof(hostname));
    res = gethostname(hostname, sizeof(hostname));
    if(res < 0){
        perror("gethostname is error\n");
    }
    printf("hostname:[%]\n",hostname);

    res = sethostname("sgyt", sizeof("sgyt"));

    //memset(hostname,0x00, sizeof(hostname));
    gethostname(hostname, sizeof(hostname));
    printf("hostname:[%]\n",hostname);
    return 0;
}
